<?php
class Frontend extends CI_Controller {
	function __construct()
	{
		parent::__construct();
	}
	function index()
	{
		$this->inicio();
	}
	function inicio($page = 'inicio')
	{
		$data['encabezado'] = "Heading...";
		$data['todo'] = array('Hago una cosa','Hago la otra cosa','Por ultimo...','Hago la otra cosa');
		$data['titulo'] = ucfirst($page);
		$data['nivoSlider'] = $this->frontendmodel->getNivoSlider(TRUE);
		$data['css'] = array($page, "nivo-slider", "nivo-slider/default/default");
		$data['js'] = array("front/".$page, "jquery/jquery-1.7.1.min", "jquery/jquery.nivo.slider.pack");
		$this->load->view('frontend/templates/header', $data);
		$this->load->view('frontend/templates/menu', $data);
		$this->load->view('frontend/pages/'.$page, $data);
		$this->load->view('frontend/templates/footer', $data);
	}
	function blog($page = 'blog')
	{
		$data['encabezado'] = "Heading...";
		$data['todo'] = array('Hago una cosa','Hago la otra cosa','Por ultimo...','Hago la otra cosa');
		$data['titulo'] = ucfirst($page);
		$data['nivoSlider'] = NULL;
		$data['css'] = array($page);
		$data['js'] = array("front/".$page);
		$this->load->view('frontend/templates/header', $data);
		$this->load->view('frontend/templates/menu', $data);
		$this->load->view('frontend/pages/'.$page, $data);
		$this->load->view('frontend/templates/footer', $data);
	}
	
	function quien($page = 'quien')
	{
		$data['titulo'] = "¿Quién soy?";
		$data['nivoSlider'] = NULL;
		$data['css'] = array($page);
		$data['js'] = array("front/".$page);
		$this->load->view('frontend/templates/header', $data);
		$this->load->view('frontend/templates/menu', $data);
		$this->load->view('frontend/pages/'.$page, $data);
		$this->load->view('frontend/templates/footer', $data);
	}
	function contacto($page = 'contacto')
	{
		$data['titulo'] = ucfirst($page);
		$data['nivoSlider'] = NULL;
		$data['css'] = array($page);
		$data['js'] = array("front/".$page, "jquery/jquery-1.7.1.min", "jquery/jquery.infieldlabel.min");
		$this->load->view('frontend/templates/header', $data);
		$this->load->view('frontend/templates/menu', $data);
		$this->load->view('frontend/pages/'.$page, $data);
		$this->load->view('frontend/templates/footer', $data);
	}
	function enviarCorreo()
	{
		$this->frontendmodel->sendEmail($_POST['name'],$_POST['email'],$_POST['subject'],$_POST['content'],$_POST['website']);
		$dataMensajes = array('id_mensajes' => '',
							  'nombre' => $_POST['name'],
							  'email' => $_POST['email'],
							  'website' => $_POST['website'],
							  'asunto' => $_POST['subject'],
							  'comentario' => $_POST['content'],
							  'fecha' => strtotime("now")
							 );
		$this->db->insert('mensajes',$dataMensajes);
		redirect('contacto');
	}
	function cv($page = 'CV')
	{
		$data['titulo'] = $page;
		$data['nivoSlider'] = NULL;
		$data['css'] = array($page);
		$data['js'] = array("front/".$page);
		$this->load->view('frontend/templates/header', $data);
		$this->load->view('frontend/templates/menu', $data);
		$this->load->view('frontend/pages/'.$page, $data);
		$this->load->view('frontend/templates/footer', $data);
	}
	function login($page = 'login')
	{
		if (!$this->uri->segment(2)){
			$data['titulo'] = "Login";
			$data['css'] = array($page);
			$data['js'] = array("front/".$page);
			$this->load->view('frontend/pages/login.php',$data);
		} else {
			redirect('login');
		}
	}
	function admin($page = 'admin')
	{
		$subPage = $this->uri->segment(2,'inicio');
		$data['titulo'] = "Administracion";
		$data['query'] = $this->db->get('usuario');
		$data['css'] = array($page);
		$data['js'] = array("back/".$subPage);
		$this->load->view('backend/templates/header', $data);
		//$this->load->view('backend/templates/menu', $data);
		if ($subPage) {
			$this->load->view('backend/pages/'.$subPage.'.php',$data);
		} else {
			$this->load->view('backend/pages/inicio.php',$data);
		}
		$this->load->view('backend/templates/footer', $data);
	}
	function iniciar_sesion()
	{
		$query = $this->db->query('SELECT nickname, contrasena FROM usuario');
		$row = $query->row_array();
		if ($_POST['user'] == $row['nickname'] && $_POST['password'] == $row['contrasena']) {
			session_start();
			$_SESSION['login'] = 'kleith';
			header('Location: admin');
		} else {
			header('Location: login?error=si');
		}
	}
	function cerrar_sesion()
	{
		session_start();
		session_destroy();
		header('Location: login');
	}
}